package video.web;

public class UrlParser {
	
	public static String getSiteDomain(String videoUrl){
		if(videoUrl.contains("http://v.youku.com/v_show/"))
			return "youku";
		else if(videoUrl.contains("http://www.tudou.com/programs/view/"))
			return "tudou";
		else if(videoUrl.contains("http://www.56.com"))
			return "56";
		else if(videoUrl.contains("http://video.sina.com.cn"))
			return "sina";
		else if(videoUrl.contains("http://v.ku6.com/show"))
			return "ku6";
		else
			return "unknown";
	}
	
	
	public static String getVid(String videoUrl){
		if( getSiteDomain(videoUrl).equals("youku") )
			return videoUrl.substring( videoUrl.indexOf("id_")+3, videoUrl.indexOf(".html"));
		else if( getSiteDomain(videoUrl).equals("tudou") ){
			if( '/' == (videoUrl.charAt( videoUrl.length()-1) ) )
				videoUrl = videoUrl.substring(0, videoUrl.length()-1);
			return videoUrl.substring( videoUrl.lastIndexOf("/")+1);
		}
		else if( getSiteDomain(videoUrl).equals("56") )
			return videoUrl.substring(videoUrl.indexOf("v_")+2, videoUrl.indexOf(".html"));
		else if( getSiteDomain(videoUrl).equals("sina") )
			return videoUrl.substring(videoUrl.indexOf("b/")+2, videoUrl.indexOf(".html"));
		else if( getSiteDomain(videoUrl).equals("ku6") )
			return videoUrl.substring( videoUrl.lastIndexOf("/")+1, videoUrl.indexOf(".html"));
		else
			return "unknown";
			
	}
}
